HOSTNAME="10.10.34.29"  #数据库信息
PORT="3306"
USERNAME="root"
PASSWORD="zR@Dew4!FdcUE:k"
DBNAME="app"  #数据库名称
TABLENAME="main_table" #数据库中表的名称
# 插入数据
scp KidLearning.ipa root@10.10.34.29:/home/jenkins/jenkins/home/jiagu/release/app/abc_i/KidLearning.ipa
insert_sql="insert into ${TABLENAME}(type,url,version,size) values('abc_i','itms-services://?action=download-manifest&url=https://jenkins.lifeng.site/file/app/abc_i/${VERSION}_${BUILD_TIME}',2)"
mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${insert_sql}"

#上传蒲公英
cd ${WORKSPACE}/KidLearning/
IPANAME="KidLearning"
if [ "$UPLOAD_TYPE" = "appstore" ];
then
	echo "QRCODE=upload appstore success" > ${WORKSPACE}/env.properties
else
	 # 上传蒲公英
     RESULT=$(curl -F "file=@${IPANAME}.ipa" -F '_api_key=d45cad18dcf3ddb75b7f5adeeec8046a' https://www.pgyer.com/apiv2/app/upload)
     QR=$(echo "$RESULT" | /usr/bin/python3 -c "import json,sys;obj=json.load(sys.stdin);print(obj['data']['buildQRCodeURL']);")
     if [ "$QR" = "" ];
	 then
       RESULT=$(curl -F "file=@../${VERSION}_${BUILD_TIME}/${IPANAME}.ipa" -F '_api_key=d45cad18dcf3ddb75b7f5adeeec8046a' https://www.pgyer.com/apiv2/app/upload)
       QR=$(echo "$RESULT" | /usr/bin/python3 -c "import json,sys;obj=json.load(sys.stdin);print(obj['data']['buildQRCodeURL']);")
     fi
     echo "QRCODE=${QR}" > ${WORKSPACE}/env.properties
fi
echo "## build finish ##"